Bivariate CMAP and Forloop

This notebook has been edited to look nicer than the original, despite the strict instructions NOT to. This is in everyone's best interest... particularly mine so that nobody sees how uneccessary long and complicated and undocumented my code is

Enjoy the technical demo...


Read in libraries and data


Part 1 - Bivariate CMAP

Context: I want to colour the points based on two variables: random intercept ((Intercept)) and random slope (n_month).

Bivariate CMAP

Requirements to create custom CMAP:

Interpretation:

Green: High intercept and low slope relative to the mean. Stations which were least impacted by Covid (typically lower socio-economic status neighbourhoods) and experience a lesser increase in ridership over time.

Purple: Low intercept and high slope relative to the mean. Stations which were most impacted by Covid (typically higher socio-economic status neighbourhoods and/or commercial areas) and a stronger increase in ridership over time

Pros ad Cons

Pro: Managed to represent stations based on two variables of interest

Con: Difficult to distinguish how many stations belong in each section.

Possible Solution/Improvement: Display the number of stations in each break in legend.

Census Data

Bivariate colormas (American spelling...) are also useful for displaying categorical data - although I haven't figured out yet how to make it work because if you use categorical data (Male/Female, etc.), it doesn't like it, and there isn't much about the library online to find a solution. So to overcome this, I have created a binary variable and kept it as a numerical column raher than categorical.


Part 2 - For Loop for creating buffers using OSMNX

Aim: To create a function which would allow me to create multiple 800m walking buffers for each station in Chicago using OSMNX

Tasks:

  1. Create street network (nodes and edges) from Lat/Long point
  2. Convert street network to GeoDataFrame
  3. Create Convex Hull from GeoDataFrame
  4. Convert Convex Hull to GeoDataFrame

Great, it works... But I'm not going to do this 140 times for each station

Next: A function which can do steps 1-4 for all station and append all station buffers in to one GeoDataFrame.


My logic

Make a simpler forloop in order to achieve what i finally wanted - creating this function took several hours to complete.

I create a basic function and incremetaly make it more complex until i achieve what i want

Example:

  1. Create a function which would print the Latitude of all rows (wihtout forloop)
  2. Create a function which would print out Latitude of all rows (with forloop) and append to list
  3. Create a function which would append Latitude of all rows to DataFrame